﻿@using Pyramid.Bll
@using Pyramid.Models
@using Pyramid.Mvc.Html
@model StaffSalaryViewModel
@{
	var qm = (StaffMonthlyQueryModel) ViewBag.QueryModel;
	var date = DateTime.Now.AddMonths(-1);
	var listHelper = new SelectListHelper();

	var summaries = Model.Summaries.ToList();
	var details = Model.Details.ToList();
	var master = Model.Master;
	var parts = Model.SalaryParts.ToList();

	var status = master == null ? "未统计" : (master.StatusEnum == FinanceStatus.UnSettled ? "已统计" : "已结算");
}

<div class="pageHeader">
	@using (Html.BeginForm("CalcPage", "StaffSalary", FormMethod.Post, new {onsubmit = "return navTabSearch(this);"}))
	{
		<div class="searchBar">
			<table class="searchContent">
				<tr>
					<td>年份：</td>
					<td>@Html.DropDownListForRange("year", 2010, date.Year, qm.Year)</td>
					<td>月份：</td>
					<td>@Html.DropDownListForRange("month", 1, 12, qm.Month)</td>
					<td>查询关键词：<input type="text" name="keywords" rel="pagerForm" value="@qm.Keywords" /></td>
					<td>
						@Html.DropDownList("departmentId", listHelper.Departments(qm.DepartmentId, true), new {@class = "combox"})
					</td>
					<td>
						@Html.DropDownList("positionId", listHelper.StaffPositions(qm.PositionId, true), new {@class = "combox"})
					</td>
					<td>
						<div class="buttonActive">
							<div class="buttonContent">
								<button type="submit">查询</button>
							</div>
						</div>
					</td>
				</tr>
			</table>
		</div>
	}
</div>
<div class="pageContent">
	<div class="pageContentBar">
		<div class="title">@(string.Format("{0}年{1}月份业绩统计", qm.Year, qm.Month))</div>
		<div>
			当前状态：@status
		</div>
		<div class="toolbar">
			@if (master == null || master.StatusEnum == FinanceStatus.UnSettled)
			{
				using (Html.BeginForm("Gather", "Achievement", FormMethod.Post, new {onsubmit = "return validateCallback(this, navTabAjaxDone);", id = "gatherForm"}))
				{
				<div>
					@Html.Hidden("year", qm.Year)
					@Html.Hidden("month", qm.Month)
				</div>
				<div class="buttonActive">
					<div class="buttonContent">
						<button type="submit">&nbsp;&nbsp;@(master != null ? "重新统计" : "立即统计")&nbsp;&nbsp;</button>
					</div>
				</div>
				}
			}
			@if (master != null && master.StatusEnum == FinanceStatus.UnSettled)
			{
				using (Html.BeginForm("Settle", "Achievement", FormMethod.Post, new {onsubmit = "return validateCallback(this, navTabAjaxDone);", id = "settleForm"}))
				{
				<div>
					@Html.Hidden("id", master.Id)
				</div>
				<div class="buttonActive">
					<div class="buttonContent">
						<button type="submit">&nbsp;&nbsp;结算&nbsp;&nbsp;</button>
					</div>
				</div>
				}
			}
		</div>
	</div>
	<table class="table" width="100%" layouth="110">
		<thead>
			<tr>
				<th>员工编码</th>
				<th>员工姓名</th>
				<th>性别</th>
				<th>所属部门</th>
				<th>职位</th>
				@foreach (var part in parts)
				{
					<th>@part.Name</th>
				}
				<th>合计</th>
			</tr>
		</thead>
		<tbody>
			@foreach (var summary in summaries)
			{
				<tr>
					<td>@summary.StaffCode</td>
					<td>@summary.StaffName</td>
					<td>@summary.GenderString</td>
					<td>@summary.DepartmentName</td>
					<td>@summary.PositionName</td>
					@foreach (var detail in parts.Select(part => details.FirstOrDefault(x => x.StaffId == summary.StaffId && x.PartId == part.Id)))
					{
						<td>@(detail == null ? "" : detail.Value.ToString("C"))</td>
					}
					<td>@summary.TotalSalary.ToString("C")</td>
				</tr>
			}
		</tbody>
	</table>
</div>
